package com.yowasa.xiuxian.engine.battle.buff;

import com.yowasa.xiuxian.annoations.Buff;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.TempUserBattle;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;


@Buff(name = "噬魔",type = 2)
public class ShiMoBuff implements BuffInterface {

    @Override
    public void effectBattleInfo(BuffContent content, TempUserBattle userBattle) {
        userBattle.setSpell((int) (userBattle.getSpell() * 1.2));
    }

    //回合开始时额外结算
    @Override
    public void beforeBuffAction(UserBattleContent first, UserBattleContent second, BattleContent content) {
        Integer flag = (Integer) first.getFlag().get("魔阴身");
        if(flag > 0){
            Long round = Math.round(first.getBattleInfo().getHp() * 0.06);
            first.getBattleInfo().setChp(Math.max(first.getBattleInfo().getChp() - round.intValue(),200));
            content.getMsgLog().add(first.getUserBO().getName() +"因魔阴身失去了"+round+"点hp");
        }
    }


    //防御类buff处理
    @Override
    public int defendBuffAction(UserBattleContent user, UserBattleContent battleUser, int dmg) {
        Integer flag = (Integer) user.getFlag().get("魔阴身");
        if(dmg > flag){
            user.getFlag().put("魔阴身",0);
            BuffContent buffContent = user.getBuff().get("噬魔");
            buffContent.setNum(0);
            buffContent.setDuration(0);
            return dmg - flag;
        }else {
            user.getFlag().put("魔阴身",flag - dmg);
            return 0;
        }
    }
}
